#include "stdafx.h"

#include "IComponentSystem.h"
#include "IComponent.h"

namespace ZeEngine
{
    u32 IComponentSystem::m_currentID = 0;

    IComponentSystem::IComponentSystem() : m_id(0), m_requiredComponents(0), m_needAtLeastOneComponent(0)
    {
        m_id = m_currentID++;
    }

    void IComponentSystem::AddRequiredComponent(const std::string& name)
    {
        m_requiredComponents |= IComponent::GetAndCreateComponentType(name);
    }

    void IComponentSystem::AddNeedAtLeastOneComponent(const std::string& name)
    {
        m_needAtLeastOneComponent |= IComponent::GetAndCreateComponentType(name);
    }

    bool IComponentSystem::IsEntitySupported(const Entity* pEntity)
    {
        bool fSupported = false;

        if (pEntity)
        {
            fSupported = pEntity->SupportsAllComponents(m_requiredComponents) && (!m_needAtLeastOneComponent || pEntity->SupportsAtLeastOneComponent(m_needAtLeastOneComponent));
        }

        return fSupported;
    }
};